package com.amc.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import com.amc.constant.MerchantConstant;
import com.amc.entity.Merchant;
import com.amc.service.IMerchantService;
import com.amc.service.impl.MerchantServiceImpl;
import com.amc.utils.JsonUtil;

public class ConsumerMessageListener implements MessageListener {

	IMerchantService service = new MerchantServiceImpl();

	public ConsumerMessageListener() {

	}

	@Override
	public void onMessage(Message message) {
		TextMessage tm = (TextMessage) message;
		boolean result = false;
		try {
			System.out.println("[JMS] Receive Message: " + tm.getText());
			Merchant merchant = JsonUtil.jsonToObject(tm.getText());
			merchant.setAuditStatus(MerchantConstant.AUDIT_STATUS_WAIT);
			merchant.setIsBlack(MerchantConstant.WHITE_LIST);
			result = service.merchantApply(merchant);
			System.out.println("[JMS] Insert result: " + result);
			
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
